home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / jnos110g.zip / FILES.C < prev    next >
C/C++ Source or Header  |  1994-08-26  |  27KB  |  791 lines

  1. /* System-dependent definitions of various files, spool directories, etc */
  2. /* Mods by PA0GRI */
  3. /* Modified to allow for configurable file names/locations - WG7J */
  4. #include "global.h"
  5. #include "netuser.h"
  6. #include "files.h"
  7. #include "mailbox.h"
  8.   
  9. #ifdef  MSDOS
  10. char System[] = "MSDOS";
  11. char *Startup   = "/autoexec.nos";      /* Initialization file */
  12. char *Userfile  = "/ftpusers";          /* Authorized FTP users and passwords */
  13. char *Hostfile  = "/net.rc";            /* hosts and passwords */
  14. char *Spoolqdir = "/spool";             /* Spool directory */
  15. char *Maillog   = "/spool/mail.log";    /* mail log */
  16. char *Mailspool = "/spool/mail";        /* Incoming mail */
  17. char *Mailqdir  = "/spool/mqueue";      /* Outgoing mail spool */
  18. char *LogsDir   = "/logs";              /* Logs directory */
  19. char *Mailqueue = "/spool/mqueue/*.wrk";/* Outgoing mail work files */
  20. char *Routeqdir = "/spool/rqueue";      /* queue for router */
  21. char *Alias = "/alias";             /* the alias file */
  22. char *Dfile = "/domain.txt";        /* Domain cache */
  23. char *Fdir  = "/finger";            /* Finger info directory */
  24. char *Fdbase = "/finger/dbase.dat"; /* Finger database */
  25. char *Pdbase = "/spool/names.dat"; /* Personal names databases (IW5DHE) */
  26. char *Arealist  = "/spool/areas";       /* List of message areas */
  27. char *Rewritefile = "/spool/rewrite";       /* Address rewrite file */
  28. char *Ftpmotd = "/spool/ftpmotd.txt";       /* FTP message of the day */
  29. char *CmdsHelpdir  = "/help";       /* Console/Sysop commands help file directory */
  30. #ifdef MAILBOX
  31. char *Signature = "/spool/signatur";        /* Mail signature file directory */
  32. char *Historyfile = "/spool/history";       /* Message ID history file */
  33. char *Helpdir   = "/spool/help";        /* Mailbox help file directory */
  34. char *Motdfile = "/spool/motd.txt";     /* Mailbox message of the day */
  35. #ifdef USERLOG
  36. char *UDefaults = "/spool/users.dat";       /* User preference file */
  37. char *UDefbak = "/spool/users.bak";
  38. char *Mregfile = "/spool/mreg.txt";     /* Mailbox registration message */
  39. #endif
  40. #endif /* MAILBOX */
  41. #ifdef CONVERS
  42. char *Cinfo = "/finger/dbase.dat";  /* Convers user info file */
  43. char *ConvMotd = "/spool/convmotd.txt"; /* Convers Message of the Day */
  44. #endif
  45. #if (defined(POP2CLIENT) || defined(POP2SERVER) || defined(POP3CLIENT) || defined(POP3SERVER))
  46. char *Popusers  = "/popusers";          /* POP user and password file */
  47. #endif
  48. #if (defined(NNTP) || defined(NNTPS))
  49. char *Newsdir   = "/spool/news";        /* News messages and NNTP data */
  50. char *History   = "/spool/news/history";    /* NNTP article msgids and timestamps */
  51. #endif
  52. #if (defined(RLINE) || defined(MBFWD))
  53. char *Forwardfile = "/spool/forward.bbs";   /* Mail forwarding file */
  54. #endif
  55. #ifdef NETROM
  56. char *Netromfile = "/netrom.sav";       /* Netrom node save file */
  57. #endif
  58. char *Onexit = "/onexit.nos";           /* Commands to be executed on exiting */
  59. #ifdef EXPIRY
  60. char *Expirefile = "/spool/expire.dat"; /* Message expiration control file */
  61. #endif
  62. #ifdef  NNTPS
  63. char *Naccess   = "/spool/news/access";
  64. char *Active    = "/spool/news/active";     /* */
  65. char *Pointer   = "/spool/news/pointer";    /* */
  66. char *NInfo = "/spool/news/info";       /* */
  67. char *Nhelp = "/spool/news/help";       /* */
  68. char *Forward   = "/spool/news/forward";    /* */
  69. char *Poll  = "/spool/news/poll";       /* */
  70. #endif
  71. char Eol[]  = "\r\n";
  72. #define SEPARATOR   "/"
  73. #define ROOTDIR "/"
  74. #endif
  75.   
  76. #ifdef  UNIX
  77. char System[] = "UNIX";
  78. char *Startup   = "./startup.nos";      /* Initialization file */
  79. char *Config    = "./config.nos";       /* Device configuration list */
  80. char *Hostfile  = "./net.rc";           /* hosts and passwords */
  81. char *Userfile  = "./ftpusers";
  82. char *Ftpmotd   = "./ftpmotd.txt";       /* FTP message of the day */
  83. char *CmdsHelpdir  = "./help";           /* Console/Sysop commands help file directory */
  84. char *Mailspool = "./mail";
  85. char *Maillog   = "./mail.log";         /* mail log */
  86. char *Mailqdir  = "./mqueue";
  87. char *Mailqueue = "./mqueue/*.wrk";
  88. char *Routeqdir = "./rqueue";           /* queue for router */
  89. char *Alias = "./alias";            /* the alias file */
  90. char *Dfile = "./domain.txt";       /* Domain cache */
  91. char *Fdir  = "./finger";           /* Finger info directory */
  92. char *Motdfile  = "./motd.txt";     /* Mailbox message of the day */
  93. char *Fdbase = "./finger/dbase.dat"; /* Finger database */
  94. char *Arealist  = "./areas";            /* List of message areas */
  95. char *Helpdir   = "./help";         /* Mailbox help file directory */
  96. char *Rewritefile = "./rewrite";        /* Address rewrite file */
  97. char *Signature = "./signatur";         /* Mail signature file directory */
  98. char *Popusers  = "./popusers";         /* POP user and password file */
  99. char *Newsdir   = "./news";         /* News messages and NNTP data */
  100. char *Forwardfile = "./forward.bbs";        /* Mail forwarding file */
  101. char *Historyfile = "./history";        /* Message ID history file */
  102. char *Netromfile = "./netrom.sav";      /* Netrom node save file */
  103. char *UDefaults = "./users.dat";       /* User preference file */
  104. char *UDefbak = "./users.bak";
  105. #ifdef CONVERS
  106. char *Cinfo = "./finger/dbase.dat";  /* Convers user info file */
  107. char *ConfMotd = "./spool/convmotd.txt";
  108. #endif
  109. char *Onexit = "./onexit.nos";           /* Commands to be executed on exiting */
  110. char *Expirefile = "./expire.dat"; /* Message expiration control file */
  111. #if (defined(NNTP) || defined(NNTPS))
  112. char *History   = "/spool/news/history";    /* NNTP article msgids and timestamps */
  113. #endif
  114. #ifdef  NNTPS
  115. char *Naccess   = "/spool/news/access";
  116. char *Active    = "/spool/news/active";     /* */
  117. char *Pointer   = "/spool/news/pointer";    /* */
  118. char *NInfo = "/spool/news/info";       /* */
  119. char *Nhelp = "/spool/news/help";       /* */
  120. char *Forward   = "/spool/news/forward";    /* */
  121. char *Poll  = "/spool/news/poll";       /* */
  122. #endif /* NNTPS */
  123. char Eol[]  = "\n";
  124. #define SEPARATOR   "/"
  125. #define ROOTDIR "."
  126.   
  127. #endif /* UNIX */
  128.   
  129. #ifdef  AMIGA
  130. char System[] = "AMIGA";
  131. char *Startup   = "TCPIP:nos-startup";
  132. char *Config    = "TCPIP:config.nos";       /* Device configuration list */
  133. char *Hostfile  = "TCPIP:net.rc";       /* hosts and passwords */
  134. char *Userfile  = "TCPIP:ftpusers";
  135. char *Mailspool = "TCPIP:spool/mail";
  136. char *Maillog   = "TCPIP:spool/mail.log";
  137. char *Mailqdir  = "TCPIP:spool/mqueue";
  138. char *Mailqueue = "TCPIP:spool/mqueue/#?.wrk";
  139. char *Routeqdir = "TCPIP:spool/rqueue";     /* queue for router */
  140. char *Alias = "TCPIP:alias";        /* the alias file */
  141. char *Dfile = "TCPIP:domain.txt";       /* Domain cache */
  142. char *Fdir  = "TCPIP:finger";       /* Finger info directory */
  143. char *Fdbase = "TCPIP:finger/dbase.dat"; /* Finger database */
  144. char *CmdsHelpdir  = "TCPIP:help";       /* Console/Sysop commands help file directory */
  145. char *Arealist  = "TCPIP:spool/areas";      /* List of message areas */
  146. char *Helpdir   = "TCPIP:spool/help";       /* Mailbox help file directory */
  147. char *Rewritefile = "TCPIP:spool/rewrite";  /* Address rewrite file */
  148. char *Signature = "TCPIP:spool/signatur";   /* Mail signature file directory */
  149. char *Popusers  = "TCPIP:/popusers";        /* POP user and password file */
  150. char *Newsdir   = "TCPIP:spool/news";       /* News messages and NNTP data */
  151. char *Forwardfile = "TCPIP:spool/forward.bbs";  /* Mail forwarding file */
  152. char *Historyfile = "TCPIP:spool/history";  /* Message ID history file */
  153. char *UDefaults = "TCPIP:spool/users.dat";  /* User preference file */
  154. char *Netromfile = "TCPIP:netrom.sav";      /* Netrom node save file */
  155. char *Onexit = "TCPIP:onexit.nos";           /* Commands to be executed on exiting */
  156. char *Expirefile = "TCPIP:spool/expire.dat"; /* Message expiration control file */
  157. #if (defined(NNTP) || defined(NNTPS))
  158. char *History   = "TCPIP:spool/news/history";    /* NNTP article msgids and timestamps */
  159. #endif
  160. #ifdef  NNTPS
  161. char *Active    = "TCPIP:spool/news/active";     /* */
  162. char *Pointer   = "TCPIP:spool/news/pointer";    /* */
  163. char *NInfo = "TCPIP:spool/news/info";       /* */
  164. char *Nhelp = "TCPIP:spool/news/help";       /* */
  165. char *Forward   = "TCPIP:spool/news/forward";    /* */
  166. char *Poll  = "TCPIP:spool/news/poll";       /* */
  167. #endif
  168. char Eol[]  = "\r\n";
  169. #define SEPARATOR   "/"
  170. #endif
  171.   
  172. #ifdef  MAC
  173. char System[] = "MACOS";
  174. char *Startup   = "Mikes Hard Disk:nos.start";
  175. char *Config    = "Mikes Hard Disk:config.nos"; /* Device configuration list */
  176. char *Hostfile  = "Mikes Hard Disk:net.rc"; /* hosts and passwords */
  177. char *Userfile  = "Mikes Hard Disk:ftpusers";
  178. char *Mailspool = "Mikes Hard Disk:spool:mail:";
  179. char *Maillog   = "Mikes Hard Disk:spool:mail.log:";
  180. char *Mailqdir  = "Mikes Hard Disk:spool:mqueue:";
  181. char *Mailqueue = "Mikes Hard Disk:spool:mqueue:*.wrk";
  182. char *Routeqdir = "Mikes Hard Disk:spool/rqueue:";  /* queue for router */
  183. char *Alias = "Mikes Hard Disk:alias";      /* the alias file */
  184. char *Dfile = "Mikes Hard Disk:domain:txt";     /* Domain cache */
  185. char *Fdir  = "Mikes Hard Disk:finger";     /* Finger info directory */
  186. char *Fdbase = "Mikes Hard Disk:finger/dbase.dat"; /* Finger database */
  187. char *CmdsHelpdir  = "Mikes Hard Disk:help";       /* Console/Sysop commands help file directory */
  188. char *Arealist  = "Mikes Hard Disk:spool/areas";    /* List of message areas */
  189. char *Helpdir   = "Mikes Hard Disk:spool/help";     /* Mailbox help file directory */
  190. char *Rewritefile = "Mikes Hard Disk:spool/rewrite";    /* Address rewrite file */
  191. char *Signature = "Mikes Hard Disk:spool/signatur"; /* Mail signature file directory */
  192. char *Popusers  = "Mikes Hard Disk:/popusers";      /* POP user and password file */
  193. char *Newsdir   = "Mikes Hard Disk:spool/news"; /* News messages and NNTP data */
  194. char *Forwardfile = "Mikes Hard Disk:spool/forward.bbs"; /* Mail forwarding file */
  195. char *Historyfile = "Mikes Hard Disk:spool/history";    /* Message ID history file */
  196. char *UDefaults = "Mikes Hard Disk:spool/users.dat";  /* User preference file */
  197. char *Netromfile = "Mikes Hard Disk:netrom.sav";    /* Netrom node save file */
  198. char *Onexit = "Mikes Hard Disk:onexit.nos";           /* Commands to be executed on exiting */
  199. char *Expirefile = "Mikes Hard Disk:spool/expire.dat"; /* Message expiration control file */
  200. #if (defined(NNTP) || defined(NNTPS))
  201. char *History   = "Mikes Hard Disk:spool/news/history";/* NNTP article msgids and timestamps */
  202. #endif
  203. #ifdef  NNTPS
  204. char *Naccess   = "Mikes Hard Disk:spool/news/access";
  205. char *Active    = "Mikes Hard Disk:spool/news/active";      /* */
  206. char *Pointer   = "Mikes Hard Disk:spool/news/pointer"; /* */
  207. char *NInfo = "Mikes Hard Disk:spool/news/info";        /* */
  208. char *Nhelp = "Mikes Hard Disk:spool/news/help";        /* */
  209. char *Forward   = "Mikes Hard Disk:spool/news/forward"; /* */
  210. char *Poll  = "Mikes Hard Disk:spool/news/poll";        /* */
  211. #endif
  212. char Eol[]  = "\r";
  213. #define SEPARATOR   ":"
  214. #endif
  215.   
  216. static char *rootdir = ROOTDIR;
  217. static int Assigned;
  218. static int Initroot;
  219.   
  220. static void setname __ARGS((char *name,char *file));
  221. static void tabs_to_spaces __ARGS((char *p));
  222. void assign_filenames __ARGS((char *config));
  223.   
  224. extern void undosify __ARGS((char *s));
  225.   
  226. /* Establish a root directory other than the default. Can only be called
  227.  * once, at startup time
  228.  */
  229. void
  230. initroot(root)
  231. char *root;
  232. {
  233.     if(Assigned) {
  234.         tputs("-f option used, -d ignored !\n");
  235.         return;
  236.     }
  237. #ifdef  MSDOS
  238.     undosify(root);
  239. #endif
  240.     rootdir = strdup( root );
  241.   
  242.     Startup = rootdircat(Startup);
  243.     Userfile = rootdircat(Userfile);
  244.     Hostfile = rootdircat(Hostfile);
  245.     Maillog = rootdircat(Maillog);
  246.     Spoolqdir = rootdircat(Spoolqdir);
  247.     Mailspool = rootdircat(Mailspool);
  248.     Mailqdir = rootdircat(Mailqdir);
  249.     LogsDir = rootdircat(LogsDir);
  250.     Mailqueue = rootdircat(Mailqueue);
  251.     Routeqdir = rootdircat(Routeqdir);
  252.     Alias = rootdircat(Alias);
  253.     Dfile = rootdircat(Dfile);
  254.     Fdir = rootdircat(Fdir);
  255.     Fdbase = rootdircat(Fdbase);
  256.     Pdbase = rootdircat(Pdbase);
  257. #ifdef MAILCMDS
  258.     Arealist = rootdircat(Arealist);
  259. #endif
  260.     Rewritefile = rootdircat(Rewritefile);
  261.     Ftpmotd = rootdircat(Ftpmotd);
  262.     CmdsHelpdir = rootdircat(CmdsHelpdir);
  263. #ifdef MAILBOX
  264.     Signature = rootdircat(Signature);
  265.     Historyfile = rootdircat(Historyfile);
  266.     Helpdir = rootdircat(Helpdir);
  267.     Motdfile = rootdircat(Motdfile);
  268. #ifdef USERLOG
  269.     UDefaults = rootdircat(UDefaults);
  270.     UDefbak = rootdircat(UDefbak);
  271.     Mregfile = rootdircat(Mregfile);
  272. #endif
  273. #endif
  274. #ifdef CONVERS
  275.     Cinfo = rootdircat(Cinfo);
  276.     ConvMotd = rootdircat(ConvMotd);
  277. #endif
  278. #if (defined(POP) || defined(POP2CLIENT) || defined(POP2SERVER) || defined(POP3CLIENT) || defined(POP3SERVER))
  279.     Popusers = rootdircat(Popusers);
  280. #endif
  281. #if (defined(NNTP) || defined(NNTPS))
  282.     Newsdir = rootdircat(Newsdir);
  283.     History = rootdircat(History);
  284. #endif
  285. #if (defined(MBFWD) || defined(RLINE))
  286.     Forwardfile = rootdircat(Forwardfile);
  287. #endif
  288. #ifdef NETROM
  289.     Netromfile = rootdircat(Netromfile);
  290. #endif
  291.     Onexit = rootdircat(Onexit);
  292. #ifdef EXPIRY
  293.     Expirefile = rootdircat(Expirefile);
  294. #endif
  295. #ifdef  NNTPS
  296.     Naccess = rootdircat(Naccess);
  297.     Active = rootdircat(Active);
  298.     Pointer = rootdircat(Pointer);
  299.     NInfo = rootdircat(NInfo);
  300.     Nhelp = rootdircat(Nhelp);
  301.     Forward = rootdircat(Forward);
  302.     Poll = rootdircat(Poll);
  303. #endif
  304.     Initroot = 1;
  305. }
  306.   
  307. /* Concatenate root, separator and arg strings into a malloc'ed output
  308.  * buffer, then remove repeated occurrences of the separator char
  309.  */
  310. char *
  311. rootdircat(filename)
  312. char *filename;
  313. {
  314.     char *out = filename;
  315.   
  316.     if(strlen(rootdir) > 0){
  317.         char *separator = SEPARATOR;
  318.         out = mallocw(strlen(rootdir)
  319.         + strlen(separator)
  320.         + strlen(filename) +1);
  321.         strcpy(out,rootdir);
  322.         strcat(out,separator);
  323.         strcat(out,filename);
  324.         if(*separator != '\0'){
  325.             char *p1, *p2;
  326.         /* Remove any repeated occurrences */
  327.             p1 = p2 = out;
  328.             while(*p2 != '\0'){
  329.                 *p1++ = *p2++;
  330.                 while(p2[0] == p2[-1] && p2[0] == *separator)
  331.                     p2++;
  332.             }
  333.             *p1 = '\0';
  334.         }
  335.     }
  336.     return out;
  337. }
  338.   
  339. #ifdef PPP
  340.   
  341. #ifdef notdef
  342. /* Read through FTPUSERS looking for user record
  343.  * Returns line which matches username, or NULLCHAR when no match.
  344.  * Each of the other variables must be copied before freeing the line.
  345.  */
  346. char *
  347. userlookup(username,password,directory,permission,ip_address)
  348. char *username;
  349. char **password;
  350. char **directory;
  351. long *permission;
  352. int32 *ip_address;
  353. {
  354.     FILE *fp;
  355.     char *buf;
  356.     char *cp;
  357.   
  358.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  359.         /* Userfile doesn't exist */
  360.         return NULLCHAR;
  361.   
  362.     buf = mallocw(128);
  363.     while ( fgets(buf,128,fp) != NULLCHAR ){
  364.         if(*buf == '#')
  365.             continue;   /* Comment */
  366.   
  367.         if((cp = strchr(buf,' ')) == NULLCHAR)
  368.             /* Bogus entry */
  369.             continue;
  370.         *cp++ = '\0';       /* Now points to password */
  371.   
  372.         if( stricmp(username,buf) == 0 )
  373.             break;      /* Found user */
  374.     }
  375.     if(feof(fp)){
  376.         /* username not found in file */
  377.         fclose(fp);
  378.         free(buf);
  379.         return NULLCHAR;
  380.     }
  381.     fclose(fp);
  382.   
  383.     if ( password != NULL )
  384.         *password = cp;
  385.   
  386.     /* Look for space after password field in file */
  387.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  388.         /* Invalid file entry */
  389.         free(buf);
  390.         return NULLCHAR;
  391.     }
  392.     *cp++ = '\0';   /* Now points to directory field */
  393.   
  394.     if ( directory != NULL )
  395.         *directory = cp;
  396.   
  397.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  398.         /* Permission field missing */
  399.         free(buf);
  400.         return NULLCHAR;
  401.     }
  402.     *cp++ = '\0';   /* now points to permission field */
  403.   
  404.     if (permission != NULL )
  405.         *permission = strtol( cp, NULLCHARP, 0 );
  406.   
  407.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  408.         /* IP address missing */
  409.         if ( ip_address != NULL )
  410.             *ip_address = 0L;
  411.     } else {
  412.         *cp++ = '\0';   /* now points at IP address field */
  413.         if ( ip_address != NULL )
  414.             *ip_address = resolve( cp );
  415.     }
  416.     return buf;
  417. }
  418. #endif
  419.   
  420. /* Read through FTPUSERS looking for user record
  421.  * Returns line which matches username, or NULLCHAR when no match.
  422.  * Each of the other variables must be copied before freeing the line.
  423.  */
  424. char *
  425. userlookup(username,password,directory,permission,ip_address)
  426. char *username;
  427. char **password;
  428. char **directory;
  429. long   *permission;
  430. int32 *ip_address;
  431. {
  432.     FILE *fp;
  433.     char *buf;
  434.     char *cp;
  435.     char *universal = NULLCHAR;
  436.   
  437.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  438.         /* Userfile doesn't exist */
  439.         return NULLCHAR;
  440.   
  441.     buf = mallocw(128);
  442.     while ( fgets(buf,128,fp) != NULLCHAR ){
  443.         if(*buf == '#')
  444.             continue;   /* Comment */
  445.   
  446.         if((cp = strpbrk(buf," \t")) == NULLCHAR)
  447.             /* Bogus entry */
  448.             continue;
  449.         *cp++ = '\0';       /* Now points to password */
  450.   
  451.         if( stricmp(username,buf) == 0 )
  452.             break;      /* Found user */
  453.         if(stricmp("univperm",buf) == 0)
  454.             universal = strdup(cp); /* remember their anon entry */
  455.     }
  456.     if((universal == NULLCHAR) && (feof(fp))){
  457.         /* username not found in file, nor was univperm */
  458.         fclose(fp);
  459.         free(buf);
  460.         return NULLCHAR;
  461.     }
  462.     if(feof(fp)){
  463.         /* restore anonymous to the buffer */
  464.         strcpy(cp = buf, universal);
  465.         free(universal);
  466.         universal = NULLCHAR;
  467.     }
  468.     if(universal != NULLCHAR)
  469.         free(universal);
  470.     fclose(fp);
  471.   
  472.     cp = skipwhite(cp);
  473.     if ( password != NULL )
  474.         *password = cp;
  475.   
  476.     /* Look for space or tab after password field in file */
  477.     if((cp = strpbrk(cp," \t")) == NULLCHAR)    {
  478.         /* Invalid file entry */
  479.         free(buf);
  480.         return NULLCHAR;
  481.     }
  482.     *cp++ = '\0';   /* Now points to directory field */
  483.     cp=skipwhite(cp);
  484.   
  485.     if ( directory != NULL )
  486.         *directory = cp;
  487.   
  488.     if((cp = strpbrk(cp," \t")) == NULLCHAR)    {
  489.         /* Permission field missing */
  490.         free(buf);
  491.         return NULLCHAR;
  492.     }
  493.     *cp++ = '\0';   /* now points to permission field */
  494.     cp=skipwhite(cp);
  495.   
  496.     if ( permission != NULL )   {
  497.         if(!strnicmp(cp,"0x",2))
  498.             *permission = htol(cp);
  499.         else
  500.             *permission = atol(cp);
  501.     }
  502.   
  503.     if((cp = strpbrk(cp," \t")) == NULLCHAR)    {
  504.         /* IP address missing */
  505.         if ( ip_address != NULL )
  506.             *ip_address = 0L;
  507.     } else {
  508.         *cp++ = '\0';   /* now points at IP address field */
  509.         if ( ip_address != NULL )
  510.             *ip_address = resolve( cp );
  511.     }
  512.     return buf;
  513. }
  514.   
  515. #endif /* PPP */
  516.   
  517.   
  518. /* Subroutine for logging in the user whose name is name and password is pass.
  519.    The buffer path should be long enough to keep a line from the userfile.
  520.    If pwdignore is true, the password check will be overridden.
  521.    The return value is the permissions field or -1 if the login failed.
  522.    Path is set to point at the path field, and pwdignore will be true if no
  523.    particular password was needed for this user.
  524.  */
  525. long
  526. userlogin(name,pass,path,len,pwdignore)
  527. char *name;
  528. char *pass;
  529. char **path;
  530. int len;            /* Length of buffer pointed at by *path */
  531. int *pwdignore;
  532. {
  533.     char *cp;
  534.     FILE *fp;
  535.     char *universal = NULLCHAR;
  536.     long perm;
  537.     char *line,*user,*password,*privs,*directory;
  538.   
  539.     /* Check environment variables first - WG7J */
  540.     if((user=getenv("NOSSYSOP")) != NULL) {
  541.         if(strcmp(user,name) == 0) {
  542.             /* the right user name, now check password */
  543.             if((password=getenv("NOSPASSWD")) != NULL) {
  544.                 if(strcmp(password,pass) == 0) {
  545.                     *pwdignore = 0;
  546.                     if((directory=getenv("NOSPATH")) != NULL)
  547.                         strcpy(*path,directory);
  548.                     if((privs=getenv("NOSPRIVS")) != NULL) {
  549.                         if(strnicmp(privs,"0x",2) == 0)
  550.                             return htol(privs);
  551.                         else
  552.                             return atol(privs);
  553.                     } else
  554.                         return (FTP_READ + \
  555.                         FTP_CREATE + \
  556.                         FTP_WRITE + \
  557.                         AX25_CMD + \
  558.                         TELNET_CMD + \
  559.                         NETROM_CMD + \
  560.                         SYSOP_CMD + \
  561.                         IS_EXPERT);
  562.   
  563.                 }
  564.             }
  565.         }
  566.     }
  567.   
  568.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE) {
  569.         /* Userfile doesn't exist */
  570.         *pwdignore = 0;
  571.         return -1;
  572.     }
  573.     while(fgets(*path,len,fp),!feof(fp)){
  574.         line = skipwhite(*path);
  575.         if(*line == '#')
  576.             continue;   /* Comment */
  577.         if((password = strpbrk(line," \t")) == NULLCHAR)
  578.             /* Bogus entry */
  579.             continue;
  580.         rip(line);
  581.         *password++ = '\0';
  582.          /* Now points to spaces or tabs before password */
  583.         password = skipwhite(password);
  584.          /* Now points to password */
  585.         if(stricmp(name,line) == 0)
  586.             break;      /* Found user name */
  587.         if(stricmp("univperm",line) == 0)
  588.             universal = strdup(password); /* remember their anon entry */
  589.     }
  590.     if((universal == NULLCHAR) && (feof(fp))){
  591.         /* User name not found in file, nor was univperm */
  592.         fclose(fp);
  593.         /* No need to free universal ( == NULLCHAR ) remember !!! */
  594.         return -1;
  595.     }
  596.     if(feof(fp)){
  597.         /* restore anonymous to the buffer */
  598.         strcpy(password = *path, universal);
  599.         free(universal);
  600.         universal = NULLCHAR;
  601.     }
  602.     if(universal != NULLCHAR)
  603.         free(universal);
  604.     fclose(fp);
  605.   
  606.     /* Look for space or tab after password field in file */
  607.     if((directory = strpbrk(password," \t")) == NULLCHAR)
  608.         /* Invalid file entry */
  609.         return -1;
  610.     *directory++ = '\0';  /* Terminate password */
  611.     /* Find start of path */
  612.     directory = skipwhite(directory);
  613.     if(strlen(directory) + 1 > len )
  614.         /* not enough room for path */
  615.         return -1;
  616.   
  617.     if(strcmp(password,"*") == 0)
  618.         *pwdignore = 1;  /* User ID is password-free */
  619.     if(!(*pwdignore) && strcmp(password,pass) != 0)
  620.         /* Password required, but wrong one given */
  621.         return -1;
  622.   
  623.     /* Find permission field */
  624.     if((privs = strpbrk(directory," \t")) == NULLCHAR)
  625.         /* Permission field missing */
  626.         return -1;
  627.     /* Find start of permissions */
  628.     privs = skipwhite(privs);
  629.     if(!strnicmp(privs,"0x",2))
  630.         perm = htol(privs);
  631.     else
  632.         perm = atol(privs);
  633.   
  634.     /* Now copy the compound path, with possibly multiple paths and permissions */
  635.     strcpy(*path,directory);
  636.     dirformat(*path);
  637.   
  638.     /* Finally return the permission bits */
  639.     return perm;
  640. }
  641.   
  642. struct Nosfiles {
  643.     char *name;
  644.     char **path;
  645. };
  646.   
  647. struct Nosfiles Nfiles[] = {
  648.     "Startup",&Startup,
  649.     "Userfile",&Userfile,
  650.     "Hostfile",&Hostfile,
  651.     "Spoolqdir",&Spoolqdir,
  652.     "Maillog",&Maillog,
  653.     "Mailspool",&Mailspool,
  654.     "Mailqdir",&Mailqdir,
  655.     "LogsDir",&LogsDir,
  656.     "Mailqueue",&Mailqueue,
  657.     "Routeqdir",&Routeqdir,
  658.     "Alias",&Alias,
  659.     "Dfile",&Dfile,
  660.     "Fdir",&Fdir,
  661.     "Fdbase",&Fdbase,
  662.     "Pdbase",&Pdbase,
  663.     "Rewritefile",&Rewritefile,
  664.     "Onexit",&Onexit,
  665.     "Ftpmotd",&Ftpmotd,
  666.     "CmdsHelpdir",&CmdsHelpdir,
  667. #ifdef MAILBOX
  668.     "Signature",&Signature,
  669.     "Historyfile",&Historyfile,
  670.     "Helpdir",&Helpdir,
  671.     "Motdfile",&Motdfile,
  672. #ifdef MAILCMDS
  673.     "Arealist",&Arealist,
  674. #endif
  675. #ifdef USERLOG
  676.     "UDefaults",&UDefaults,
  677.     "UDefbak",&UDefbak,
  678.     "Mregfile",&Mregfile,
  679. #endif
  680. #endif
  681. #ifdef CONVERS
  682.     "Cinfo",&Cinfo,
  683.     "ConvMotd",&ConvMotd,
  684. #endif
  685. #if (defined(POP) || defined(POP2CLIENT) || defined(POP2SERVER) || defined(POP3CLIENT) || defined(POP3SERVER))
  686.     "Popusers",&Popusers,
  687. #endif
  688. #if (defined(NNTP) || defined(NNTPS))
  689.     "Newsdir",&Newsdir,
  690.     "History",&History,
  691. #endif
  692. #if (defined(MBFWD) || defined(RLINE))
  693.     "Forwardfile",&Forwardfile,
  694. #endif
  695. #ifdef NETROM
  696.     "Netromfile",&Netromfile,
  697. #endif
  698. #ifdef EXPIRY
  699.     "Expirefile",&Expirefile,
  700. #endif
  701. #ifdef NNTPS
  702.     "Naccess",&Naccess,
  703.     "Active",&Active,
  704.     "Pointer",&Pointer,
  705.     "NInfo",&NInfo,
  706.     "Nhelp",&Nhelp,
  707.     "Forward",&Forward,
  708.     "Poll",&Poll,
  709. #endif
  710.     NULLCHAR,
  711. };
  712.   
  713. #if defined(MSDOS) || defined(UNIX)
  714. void setname(char *name,char *file) {
  715.     int i = 0;
  716.   
  717.     while(Nfiles[i].name != NULLCHAR) {
  718.         if(strcmp(name,Nfiles[i].name) == 0) {
  719.             if(Initroot)
  720.                 free(*Nfiles[i].path);
  721.             *Nfiles[i].path = strdup(file);
  722.             return;
  723.         }
  724.         i++;
  725.     }
  726. }
  727.   
  728. void tabs_to_spaces(char *p) {
  729.     while(*p != '\0') {
  730.         if(*p == '\t')
  731.             *p = ' ';
  732.         p++;
  733.     }
  734. }
  735.   
  736. void
  737. assign_filenames(char *config) {
  738.     FILE *fp;
  739.     char *name,*file,*cp;
  740.     int line;
  741. #define BUFLEN 128
  742.     char buf[BUFLEN+1];
  743.   
  744.     undosify(config);
  745.     if((fp = fopen(config,"r")) == NULL) {
  746.         tprintf("Cannot open %\n",config);
  747.         return;
  748.     }
  749.   
  750.     line = 0;
  751.     while(fgets(buf,BUFLEN,fp) != NULL) {
  752.         line++;
  753.         if(*buf == '#')         /* comment */
  754.             continue;
  755.         rip(buf);   /* delete ending \n */
  756.         tabs_to_spaces(buf);
  757.         name = buf;
  758.         while(*name == ' ')    /* no leading spaces */
  759.             name++;
  760.         if(*name == '\0')      /* blank line */
  761.             continue;
  762.         /* Search for filename */
  763.         if((file = strchr(name,'=')) == NULL) {
  764.             tprintf("Need '=', line %d of %s.\n",line,config);
  765.             continue;
  766.         }
  767.         *file++ = '\0';
  768.         /* cut trailing spaces */
  769.         if((cp = strchr(name,' ')) != NULL)
  770.             *cp = '\0';
  771.   
  772.         /* find start of filename */
  773.         while(*file == ' ')
  774.             file++;
  775.   
  776.         if(*file == '\0')
  777.             continue;
  778.   
  779.         /* cut trailing spaces */
  780.         if((cp = strchr(file,' ')) != NULL)
  781.             *cp = '\0';
  782.   
  783.         /* Now parse the name, and assign if valid */
  784.         setname(name,file);
  785.     }
  786.     fclose(fp);
  787.     Assigned = 1;
  788. }
  789. #endif
  790.   
  791.